package com.ship.dispatch.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ship.dispatch.bean.SpYearPlanScheme;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 年度 计划方案表 Mapper 接口
 * </p>
 *
 * @author AbyssRabbit@163.com
 * @since 2023-10-17
 */
public interface SpYearPlanSchemeMapper extends BaseMapper<SpYearPlanScheme> {
    /**
     * 草稿方案
     *
     * @return
     */
    @Select("select s.* from sp_year_plan_scheme s\n" +
            "LEFT JOIN sp_year_plan_scheme_detail_history h on h.scheme_id = s.id and s.plan_id = h.plan_id and s.create_by = h.create_by\n" +
            "where  s.create_by = #{createBy} and s.is_draft = 1  and h.scheme_old_id in (select scheme_old_id from sp_year_plan_scheme_detail_history where id = #{schemeDetailId} and scheme_id= #{schemeId})\n" +
            "GROUP BY h.scheme_id")
    List<SpYearPlanScheme> getYearPlanSchemeByDraft(@Param("createBy") String createBy, @Param("schemeDetailId") Long schemeDetailId, @Param("schemeId") Long schemeId);

    /**
     * 分享方案
     *
     * @return
     */
    @Select("select s.* from sp_year_plan_scheme s\n\" +\n" +
            "            \"LEFT JOIN sp_year_plan_scheme_detail_history h on h.scheme_id = s.id and s.plan_id = h.plan_id and s.create_by = h.create_by\\n\" +\n" +
            "            \"where  s.create_by = #{createBy} and s.is_share = 1  and h.scheme_old_id in (select scheme_old_id from sp_year_plan_scheme_detail_history where id = #{schemeDetailId} and scheme_id= #{schemeId})\\n\" +\n" +
            "            \"GROUP BY h.scheme_id")
    List<SpYearPlanScheme> getYearPlanSchemeByShare(@Param("createBy") String createBy, @Param("schemeDetailId") Long schemeDetailId, @Param("schemeId") Long schemeId);
}